//
//  WYCTabBar.m
//  WYCweibo
//
//  Created by 魏云超 on 15/11/11.
//  Copyright (c) 2015年 魏云超. All rights reserved.
//

#import "WYCTabBar.h"
@interface WYCTabBar()
@property (nonatomic, weak) UIButton *plusBtn;
@end
@implementation WYCTabBar

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/
-(void)layoutSubviews{
    [super layoutSubviews];
    CGFloat tabBarW = self.frame.size.width / 5;
    CGFloat tabBarH =self.frame.size.height;
    CGFloat tabBarY = 0 ;
    NSUInteger index = 0;//索引
    //覆盖系统设置的默认值
    for (UIView *subview in self.subviews) {
        //判断是否是UITabbarButton
        if ([subview isKindOfClass:[UIControl class]]) {
            //
            CGFloat tabBarX =index *tabBarW;
            index ++;
            if (index == 2) {
                index ++;
            }
            
            subview.frame = CGRectMake(tabBarX, tabBarY, tabBarW, tabBarH);
        }
    }
    //设置加号按钮的frame
    CGPoint tempCenter = self.plusBtn.center;
    tempCenter.x = self.frame.size.width * 0.5;
    tempCenter.y = self.frame.size.height * 0.5;
    self.plusBtn.center = tempCenter;
}
#pragma lazy
-(UIButton *)plusBtn{
    if (!_plusBtn) {
        UIButton  *btn = [UIButton buttonWithType:UIButtonTypeCustom];
        
        [btn addTarget:self action:@selector(compose) forControlEvents:UIControlEventTouchUpInside];
        //设置背景图片
        [btn setImage:[UIImage imageNamed:@"tabbar_compose_icon_add" ] forState:UIControlStateNormal];
        [btn setImage:[UIImage imageNamed:@"tabbar_compose_icon_add_highlighted" ] forState:UIControlStateHighlighted];
        
        [btn setBackgroundImage:[UIImage imageNamed:@"tabbar_compose_button"] forState:UIControlStateNormal];
        [btn setBackgroundImage:[UIImage imageNamed:@"tabbar_compose_button_highlighted"] forState:UIControlStateHighlighted];
        [self addSubview:btn];
        _plusBtn = btn;
    }
    return _plusBtn;
}
-(void)compose{
    DDLogInfo(@"xxx");
}
@end















